package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.IcVolunteers;
import com.ruoyi.system.service.IIcVolunteersService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 志愿者Controller
 * 
 * @author ruoyi
 * @date 2024-07-10
 */
@Controller
@RequestMapping("/system/icVolunteers")
public class IcVolunteersController extends BaseController
{
    private String prefix = "system/icVolunteers";

    @Autowired
    private IIcVolunteersService icVolunteersService;

    @RequiresPermissions("system:icVolunteers:view")
    @GetMapping()
    public String icVolunteers()
    {
        return prefix + "/icVolunteers";
    }

    /**
     * 查询志愿者列表
     */
    @RequiresPermissions("system:icVolunteers:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IcVolunteers icVolunteers)
    {
        startPage();
        List<IcVolunteers> list = icVolunteersService.selectIcVolunteersList(icVolunteers);
        return getDataTable(list);
    }

    /**
     * 导出志愿者列表
     */
    @RequiresPermissions("system:icVolunteers:export")
    @Log(title = "志愿者", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IcVolunteers icVolunteers)
    {
        List<IcVolunteers> list = icVolunteersService.selectIcVolunteersList(icVolunteers);
        ExcelUtil<IcVolunteers> util = new ExcelUtil<IcVolunteers>(IcVolunteers.class);
        return util.exportExcel(list, "志愿者数据");
    }

    /**
     * 新增志愿者
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存志愿者
     */
    @RequiresPermissions("system:icVolunteers:add")
    @Log(title = "志愿者", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IcVolunteers icVolunteers)
    {
        return toAjax(icVolunteersService.insertIcVolunteers(icVolunteers));
    }

    /**
     * 修改志愿者
     */
    @RequiresPermissions("system:icVolunteers:edit")
    @GetMapping("/edit/{volunteerId}")
    public String edit(@PathVariable("volunteerId") Long volunteerId, ModelMap mmap)
    {
        IcVolunteers icVolunteers = icVolunteersService.selectIcVolunteersByVolunteerId(volunteerId);
        mmap.put("icVolunteers", icVolunteers);
        return prefix + "/edit";
    }

    /**
     * 修改保存志愿者
     */
    @RequiresPermissions("system:icVolunteers:edit")
    @Log(title = "志愿者", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IcVolunteers icVolunteers)
    {
        return toAjax(icVolunteersService.updateIcVolunteers(icVolunteers));
    }

    /**
     * 删除志愿者
     */
    @RequiresPermissions("system:icVolunteers:remove")
    @Log(title = "志愿者", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(icVolunteersService.deleteIcVolunteersByVolunteerIds(ids));
    }
}
